package com.example.demo.controller;


import com.example.demo.common.AppResult;
import com.example.demo.model.Board;
import com.example.demo.services.IBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "板块接口")
@Slf4j
@RestController
@RequestMapping("/board")
public class BoardController {

    //从配置文件中获取主页中显示得板块个数，默认为9

    @Value("${java-forum.index.board-num:9}")
    private Integer indexBoardNum;
    @Resource
    private IBoardService boardService;

    @ApiOperation("获取所有正常状态得板块")
    @GetMapping("/topList")
    public AppResult topList(){
        //直接调用Service
       List<Board> boards = boardService.selectByNum(indexBoardNum);
       //返回结果
        return AppResult.success(boards);
    }

    /**
     * 获取指定板块详情
     * @param id 板块Id
     * @return AppResult<Board>
     */
    @ApiOperation("获取指定板块详情")
    @GetMapping("/getById")
    public AppResult<Board> getBoardInfo(@ApiParam("板块Id") @RequestParam("id") @NonNull Long id){

        //调用Service
        Board board = boardService.selectById(id);
        //返回结果
        return AppResult.success(board);
    }
}
